<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
		xmlns:ui="http://java.sun.com/jsf/facelets"
		xmlns:h="http://java.sun.com/jsf/html"
		xmlns:f="http://java.sun.com/jsf/core"
	    xmlns:p="http://primefaces.org/ui"
	    xmlns:hf="http://happyfaces.org/happyfaces"
		xmlns:c="http://java.sun.com/jsp/jstl/core">

	<ui:composition>
		
		<!-- The required attribute is optional, 
         initialize it to false if not found. -->
	    <c:if test="${empty required}">
	        <c:set var="required" value="false" />
	    </c:if>
	    
	    <c:set var="filtersMap" value="#{backingBean.filters}" />
	    
	    <!-- Default size. -->
	    <c:if test="${empty size}">
	        <c:set var="size" value="20" />
	    </c:if>
 		
 		<!-- Clear Button. -->
	    <c:if test="${empty clearButton}">
	        <c:set var="clearButton" value="false" />
	    </c:if>
		
	    <!-- No popup is set. -->
	    <c:if test="${empty popup}">
	        <c:set var="popup" value="false" />
	    </c:if>
	    
	    <!-- Search with entity popup -->
	    <c:if test="${popup}">
			<c:set var="childEntity" value="#{entity[field]}" />
			<p:outputLabel for="#{field}_child" value="#{label}" />
			<h:panelGrid id="#{field}" columns="3">
				<p:inputText id="#{field}_child" value="#{filtersMap[field][childField]}" required="${required}" size="#{size}" disabled="true" />
				<p:commandButton id="selectLink" onclick="dlg.show()" icon="ui-icon-search">
				</p:commandButton>
				<p:tooltip for="selectLink" value="#{messages['commons.search']}" />
			</h:panelGrid>
		</c:if>

		<!-- Search with entity list in select box -->
	    <c:if test="${!popup}">
	    	<c:if test="${!empty listBean}">
				<p:outputLabel for="#{id}_level" value="#{label}" />
				<p:selectOneMenu id="#{id}_level" value="#{filtersMap[field]}">
					<f:selectItem itemLabel="" itemValue="" />
					<f:selectItems value="${listBean.listAll()}" var="elem" itemLabel="#{elem[childField]}" itemValue="#{elem}" />
					<f:converter binding="#{entityConverter}" />
				</p:selectOneMenu>
				<ui:insert />
			</c:if>
			
	    </c:if>

    </ui:composition>

</html>
